package top.sky.log.impl;

import top.sky.log.config.LogConstant;
import org.slf4j.Logger;
import org.slf4j.MDC;
import org.slf4j.Marker;

/**
 * 抽象的Logger类。
 *
 * @author shijin.liu
 * @since 2023-07-01
 */
public abstract class AbstractLogger implements Logger {
    protected Logger logger;

    public AbstractLogger(Logger logger) {
        this.logger = logger;
    }

    @Override
    public String getName() {
        return logger.getName();
    }

    @Override
    public boolean isTraceEnabled() {
        return logger.isTraceEnabled();
    }

    @Override
    public void trace(String msg) {
        logger.trace(msg);
    }

    @Override
    public void trace(String format, Object arg) {
        logger.trace(format, arg);
    }

    @Override
    public void trace(String format, Object arg1, Object arg2) {
        logger.trace(format, arg1, arg2);
    }

    @Override
    public void trace(String format, Object... arguments) {
        logger.trace(format, arguments);
    }

    @Override
    public void trace(String msg, Throwable t) {
        logger.trace(msg, t);
    }

    @Override
    public boolean isTraceEnabled(Marker marker) {
        return logger.isTraceEnabled(marker);
    }

    @Override
    public void trace(Marker marker, String msg) {
        logger.trace(marker, msg);
    }

    @Override
    public void trace(Marker marker, String format, Object arg) {
        logger.trace(marker, format, arg);
    }

    @Override
    public void trace(Marker marker, String format, Object arg1, Object arg2) {
        logger.trace(marker, format, arg1, arg2);
    }

    @Override
    public void trace(Marker marker, String format, Object... argArray) {
        logger.trace(marker, format, argArray);
    }

    @Override
    public void trace(Marker marker, String msg, Throwable t) {
        logger.trace(marker, msg, t);
    }

    @Override
    public boolean isDebugEnabled(Marker marker) {
        return logger.isDebugEnabled(marker);
    }

    @Override
    public void debug(Marker marker, String msg) {
        logger.debug(marker, msg);
    }

    @Override
    public void debug(Marker marker, String format, Object arg) {
        logger.debug(marker, format, arg);
    }

    @Override
    public void debug(Marker marker, String format, Object arg1, Object arg2) {
        logger.debug(marker, format, arg1, arg2);
    }

    @Override
    public void debug(Marker marker, String format, Object... arguments) {
        logger.debug(marker, format, arguments);
    }

    @Override
    public void debug(Marker marker, String msg, Throwable t) {
        logger.debug(marker, msg, t);
    }

    @Override
    public boolean isInfoEnabled(Marker marker) {
        return logger.isInfoEnabled(marker);
    }

    @Override
    public void info(Marker marker, String msg) {
        logger.info(marker, msg);
    }

    @Override
    public void info(Marker marker, String format, Object arg) {
        logger.info(marker, format, arg);
    }

    @Override
    public void info(Marker marker, String format, Object arg1, Object arg2) {
        logger.info(marker, format, arg1, arg2);
    }

    @Override
    public void info(Marker marker, String format, Object... arguments) {
        logger.info(marker, format, arguments);
    }

    @Override
    public void info(Marker marker, String msg, Throwable t) {
        logger.info(marker, msg, t);
    }

    @Override
    public boolean isWarnEnabled(Marker marker) {
        return logger.isWarnEnabled(marker);
    }

    @Override
    public void warn(Marker marker, String msg) {
        logger.warn(marker, msg);
    }

    @Override
    public void warn(Marker marker, String format, Object arg) {
        logger.warn(marker, format, arg);
    }

    @Override
    public void warn(Marker marker, String format, Object arg1, Object arg2) {
        logger.warn(marker, format, arg1, arg2);
    }

    @Override
    public void warn(Marker marker, String format, Object... arguments) {
        logger.warn(marker, format, arguments);
    }

    @Override
    public void warn(Marker marker, String msg, Throwable t) {
        logger.warn(marker, msg, t);
    }

    @Override
    public boolean isErrorEnabled(Marker marker) {
        return logger.isErrorEnabled(marker);
    }

    @Override
    public void error(Marker marker, String msg) {
        logger.error(marker, msg);
    }

    @Override
    public void error(Marker marker, String format, Object arg) {
        logger.error(marker, format, arg);
    }

    @Override
    public void error(Marker marker, String format, Object arg1, Object arg2) {
        logger.error(marker, format, arg1, arg2);
    }

    @Override
    public void error(Marker marker, String format, Object... arguments) {
        logger.error(marker, format, arguments);
    }

    @Override
    public void error(Marker marker, String msg, Throwable t) {
        logger.error(marker, msg, t);
    }

    protected String getTransactionId() {
        return MDC.get(LogConstant.MDC_KEY_TRANSACTION_ID);
    }

    protected void printLog(String transactionId, Object message) {
        if (logger.isDebugEnabled()) {
            logger.debug("[--> transactionId:{}] --> {}", transactionId, message);
            return;
        }
        if (logger.isInfoEnabled()) {
            logger.info("[--> transactionId:{}] --> {}", transactionId, message);
            return;
        }
        if (logger.isWarnEnabled()) {
            logger.warn("[--> transactionId:{}] --> {}", transactionId, message);
            return;
        }
        if (logger.isErrorEnabled()) {
            logger.error("[--> transactionId:{}] --> {}", transactionId, message);
            return;
        }
    }

    protected void printLog(String transactionId, String format, Object message) {
        if (logger.isDebugEnabled()) {
            logger.debug("[--> transactionId:{}] --> " + format, transactionId, message);
            return;
        }
        if (logger.isInfoEnabled()) {
            logger.info("[--> transactionId:{}] --> " + format, transactionId, message);
            return;
        }
        if (logger.isWarnEnabled()) {
            logger.warn("[--> transactionId:{}] --> " + format, transactionId, message);
            return;
        }
        if (logger.isErrorEnabled()) {
            logger.error("[--> transactionId:{}] --> " + format, transactionId, message);
            return;
        }
    }

    protected void printLog(String transactionId, String format, Object arg1, Object arg2) {
        if (logger.isDebugEnabled()) {
            logger.debug("[--> transactionId:{}] --> " + format, transactionId, arg1, arg2);
            return;
        }
        if (logger.isInfoEnabled()) {
            logger.info("[--> transactionId:{}] --> " + format, transactionId, arg1, arg2);
            return;
        }
        if (logger.isWarnEnabled()) {
            logger.warn("[--> transactionId:{}] --> " + format, transactionId, arg1, arg2);
            return;
        }
        if (logger.isErrorEnabled()) {
            logger.error("[--> transactionId:{}] --> " + format, transactionId, arg1, arg2);
            return;
        }
    }

    protected void printLog(String transactionId, String format, Object... argArray) {
        if (logger.isDebugEnabled()) {
            logger.debug("[--> transactionId:" + transactionId + "] --> " + format, argArray);
            return;
        }
        if (logger.isInfoEnabled()) {
            logger.info("[--> transactionId:" + transactionId + "] --> " + format, argArray);
            return;
        }
        if (logger.isWarnEnabled()) {
            logger.warn("[--> transactionId:" + transactionId + "] --> " + format, argArray);
            return;
        }
        if (logger.isErrorEnabled()) {
            logger.error("[--> transactionId:" + transactionId + "] --> " + format, argArray);
            return;
        }
    }

    protected void printLog(String transactionId, String msg, Throwable t) {
        if (logger.isDebugEnabled()) {
            logger.debug("[--> transactionId:" + transactionId + "] --> " + msg, t);
            return;
        }
        if (logger.isInfoEnabled()) {
            logger.info("[--> transactionId:" + transactionId + "] --> " + msg, t);
            return;
        }
        if (logger.isWarnEnabled()) {
            logger.warn("[--> transactionId:" + transactionId + "] --> " + msg, t);
            return;
        }
        if (logger.isErrorEnabled()) {
            logger.error("[--> transactionId:" + transactionId + "] --> " + msg, t);
            return;
        }
    }
}
